package cn.e4j.modular.api.service;

import cn.e4j.core.dto.impl.Dto;
import cn.e4j.modular.api.mapper.QtpsMapper;
import cn.e4j.modular.crm.entity.GwcuT;
import cn.e4j.modular.crm.entity.MmraT;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
public class QtpsService{

    @Autowired
    QtpsMapper qtpsMapper;

    /**
     * 获取承运公司
     * @param inDto
     * @return
     */
    @Transactional(readOnly = true)
    public List<Dto> getCompany(Dto inDto) {
        return qtpsMapper.getCompany(inDto);
    }

    /**
     * 获取已运输数量
     * @param inDto
     * @return
     */
    @Transactional(readOnly = true)
    public Integer getAlready(Dto inDto) {
        return qtpsMapper.getAlready(inDto);
    }

    /**
     * 获取总订单数
     * @param inDto
     * @return
     */
    @Transactional(readOnly = true)
    public Dto getTotal(Dto inDto) {
        return qtpsMapper.getTotal(inDto);
    }

    /**
     * 获取明细
     * @param inDto
     * @return
     */
    @Transactional(readOnly = true)
    public List<Dto> getDetail(Dto inDto) {
        return qtpsMapper.getDetail(inDto);
    }

    @Transactional(readOnly = true)
    public Integer getMaxSeq(Dto inDto) {
        return qtpsMapper.getMaxSeq(inDto);
    }

    @Transactional
    public void save(List<GwcuT> gwcuts, List<MmraT> mmra_tPOS) {
        gwcuts.forEach(gwcut->{
            gwcut.insert();
        });

        mmra_tPOS.forEach(mmra->{
            mmra.insert();
        });
    }
    @Transactional(readOnly = true)
    public Integer validateProductNoInKC(Dto inDto) {
        return qtpsMapper.validateProductNoInKC(inDto);
    }

    @Transactional(readOnly = true)
    public Integer validCustomerNo(Dto inDto) {
        return qtpsMapper.validCustomerNo(inDto);
    }

    @Transactional(readOnly = true)
    public Integer ifPurchaseProduct(Dto inDto) {
        return qtpsMapper.ifPurchaseProduct(inDto);
    }

    @Transactional(readOnly = true)
    public List<Dto> getBusinessmen(Page<Object> page,Dto dto) {
        return qtpsMapper.getBusinessmen(page,dto);
    }
}
